<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
      var minimumReplacement = function(nums) {
    let n = nums.length, ans = 0
    for(let i = n - 1, last = nums[n - 1]; i >= 0 ; i--){
        if(nums[i] <= last) last = nums[i]
        else {
            let k = Math.ceil(nums[i]/last)
            ans += k - 1
            last = nums[i] / k >> 0
        }
    }
    return ans
};
  </script>
</body>
</html>